package cn.openea.perpartner.timeline.web.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.timeline.web.entity.ArcTicket;
import cn.openea.perpartner.timeline.web.entity.InsTicket;
import cn.openea.perpartner.timeline.web.entity.dto.SearchDto;
import cn.openea.perpartner.timeline.web.entity.dto.TicketDto;
import cn.openea.perpartner.timeline.web.service.ArcTicketService;
import cn.openea.perpartner.timeline.web.service.InsTicketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Weird077
 * @since 2022-12-11 22:16:28
 */
@Api(tags = "工单列表")
@RestController
@RequestMapping("/ticket")
public class TicketController extends BaseController {

    @Resource
    private InsTicketService insTicketService;
    @Resource
    private ArcTicketService arcTicketService;

    @ApiOperation(value = "我参与的-ins", notes = "分页查询工单数据-ins")
    @PostMapping("/ins/join/list")
    public TableDataInfo selectInsAll(@RequestBody SearchDto dto) {
        startPage();
        List<InsTicket> list = insTicketService.selectAll(dto);
        return getDataTable(list);
    }
    @ApiOperation(value = "我发布的-ins", notes = "分页查询工单数据-ins")
    @PostMapping("/ins/created/list")
    public TableDataInfo selectInsCreated(@RequestBody SearchDto dto) {
        startPage();
        List<InsTicket> list = insTicketService.selectCreatedList(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "我参与的-arc", notes = "分页查询工单数据-arc")
    @PostMapping("/arc/join/list")
    public TableDataInfo selectArcAll(@RequestBody  SearchDto dto) {
        startPage();
        List<ArcTicket> list = arcTicketService.selectAll(dto);
        return getDataTable(list);
    }
    @ApiOperation(value = "我发布的-arc", notes = "分页查询工单数据-arc")
    @PostMapping("/arc/created/list")
    public TableDataInfo selectArcCreated(@RequestBody SearchDto dto) {
        startPage();
        List<ArcTicket> list = arcTicketService.selectCreatedList(dto);
        return getDataTable(list);
    }
    @ApiOperation(value = "新增工单-ins", notes = "新增工单")
    @PostMapping("/save")
    public AjaxResult save(@RequestBody InsTicket ticket) {
        return success(this.insTicketService.save(ticket));
    }

    @ApiOperation(value = "归档工单-arc", notes = "归档工单")
    @PostMapping("/archival")
    public AjaxResult archival(@RequestBody TicketDto ticket) {
        return success(this.arcTicketService.archival(ticket.getTicketId()));
    }
}

